package cn.ekuma.epos.core.util;

import java.awt.Component;
import java.util.List;

import cn.ekuma.epos.businesslogic.ProductUtil;
import cn.ekuma.epos.datalogic.I_DataLogicSales;

import com.openbravo.bean.Product;
import com.openbravo.data.basic.BasicException;
import com.openbravo.data.gui.MessageInf;

import com.openbravo.pos.panels.JProductFinder;

public class ProductSwingUtil {
	
	public static Product getProductInfo(Component parent,I_DataLogicSales dlSales,String codeOrReference){
		List<Product> listProducts=null;
		try {
			listProducts=ProductUtil.getProductInfo(dlSales,codeOrReference);
		} catch (BasicException e) {
			e.printStackTrace();
			new MessageInf(e).show(parent);
			return null;
		}
		if(!listProducts.isEmpty())
			if(listProducts.size()==1)
				return listProducts.get(0);
			else{
				JProductFinder productFinder=JProductFinder.getInstance(parent, dlSales, JProductFinder.PRODUCT_NORMAL); 
			    return productFinder.setProductList(listProducts);
			}
		return null;		
	}
}
